//分页的方法
//json包括了当前页面 总页面
//分页回调方法名
//fatherDiv 分页显示的父div
function loadByPage(json,fatherdiv,methodName)
{
	
	var fDiv=$(fatherdiv);
		fDiv.empty();
	var totalPage=json.totalPage;
	if(totalPage==null || totalPage<=1)
		{
	return ;
		}
	var nowPage=json.superPage;
	var maxPage=8;
	var startPage=1;
	var tmp=0;
	var stopPage=totalPage;
	if(totalPage>maxPage)
	{
		startPage=nowPage-4;
		if(startPage<1)
			startPage=1;
		stopPage=startPage+7;
		if(stopPage>totalPage)
		{
			startPage=totalPage-maxPage;
			stopPage=totalPage;
		}
	}
	if(nowPage>totalPage)
		{
		nowPage=totalPage;
		}


	var ulP=$("<ul></ul>");
	var liP1=$("<li class='page-previous'><a title='首页' onclick='"+methodName+"(1)'  href='javascript:void(0)'>&laquo;</a></li>");
	var liP2=$("<li class='page-previous'><a title='上一页' onclick='"+methodName+"("+(nowPage-1)+")' href='javascript:void(0)'>&lsaquo;</a></li>");	
	$(ulP).append(liP1);
	$(ulP).append(liP2);
	var liP3=$("<li class='page-next'><a title='下一页' onclick='"+methodName+"("+(nowPage+1)+")' href='javascript:void(0)'>&rsaquo;</a></li>");
	var liP4=$("<li class='page-next'><a title='尾页' onclick='"+methodName+"("+totalPage+")' href='javascript:void(0)'>&raquo;</a></li>");
	for(var i=startPage;i<=stopPage;i++)
	{
	if(i==nowPage){
		var lipp=$("<li><span class='current'>"+i+"</span></li>");
			$(ulP).append(lipp);
	}else{
		var lipp=$("<li><a onclick='"+methodName+"("+i+")' href='javascript:void(0)'>"+i+"</a></li>");
		$(ulP).append(lipp);
	}
	 
	}
	//<span class="current">4</span>
	var sp=$("<span class='page-count'>共 "+totalPage+"页</span>");
	var sp1=$("<span class='page-skip'></span>");
	$(sp1).append("到第");
	$(sp1).append("<input type='text' class='pageGo' id='pageGo' value="+nowPage+" />");
	$(sp1).append("页<button onclick='"+methodName+"()'>Go</button>");

	$(ulP).append(liP3);
	$(ulP).append(liP4);
	$(fDiv).append(ulP);
	$(fDiv).append(sp);
	$(fDiv).append(sp1);
	
$("#pageGo").keyup(function(event){
		
		if(!(event.keyCode==37 ||event.keyCode==39 || event.keyCode==8 )){
		//$(this).val($(this).val().replace(/\D/g,''));
		$("#pageGo").val($(this).val().replace(/\D/g,''));
		}
		
	});
	
	//$("#pageGo").afterpaste(function(){
	//	$(this).val($(this).val().replace(/\D/g,''));
	//});
}

/* 
 2.  * 根据传入日期，要处理的天数，进行加/减计算。 
 3.  * 日期格式：XXXX年XX月XX日 
 4.  */
function addByTransDate(dateParameter, num) {
	var translateDate = "", dateString = "", monthString = "", dayString = "";
	translateDate = dateParameter.replace("-", "/").replace("-", "/");
	var newDate = new Date(translateDate);
	newDate = newDate.valueOf();
	newDate = newDate + num * 24 * 60 * 60 * 1000;
	newDate = new Date(newDate);
	//如果月份长度少于2，则前加 0 补位  
	if ((newDate.getMonth() + 1).toString().length == 1) {
		monthString = 0 + "" + (newDate.getMonth() + 1).toString();
		//alert(translateDate);
	} else {
		monthString = (newDate.getMonth() + 1).toString();
		//alert(translateDate);
	}
	//如果天数长度少于2，则前加 0 补位  
	if (newDate.getDate().toString().length == 1) {
		dayString = 0 + "" + newDate.getDate().toString();
	} else {
		dayString = newDate.getDate().toString();
	}
	dateString = newDate.getFullYear() + "-" + monthString + "-" + dayString;
	return dateString;
}



/***
 * 
 * @param {Object} dateParameter 日期
 * @param {Object} num 要减去的时间天数
 * @return {TypeName}  相减后的日期
 */
function reduceByTransDate(dateParameter, num) {
	 
	var translateDate = "", dateString = "", monthString = "", dayString = "";
	translateDate = dateParameter.replace("-", "/").replace("-", "/");
	var newDate = new Date(translateDate);
	if(num==29){
		var tmpDay=newDate.getDate();
		var byDay=new Date(newDate.getFullYear(),newDate.getMonth()+1,0).getDate();
		var mmDay=new Date(newDate.getFullYear(),newDate.getMonth(),0).getDate();
		if(tmpDay==byDay || tmpDay>mmDay){
			byDay=new Date(newDate.getFullYear(),newDate.getMonth(),0).getDate();
		}else{
			byDay=tmpDay;
		}
		newDate.setMonth(newDate.getMonth()-1,byDay);
		
	}else{
	newDate = newDate.valueOf();
	newDate = newDate - num * 24 * 60 * 60 * 1000;
	newDate = new Date(newDate);
	}

	//如果月份长度少于2，则前加 0 补位  
	if ((newDate.getMonth() + 1).toString().length == 1) {
		monthString = 0 + "" + (newDate.getMonth() + 1).toString();
		//alert(translateDate);
	} else {
		monthString = (newDate.getMonth() + 1).toString();
		//alert(translateDate);
	}
	//如果天数长度少于2，则前加 0 补位  
	if (newDate.getDate().toString().length == 1) {
		dayString = 0 + "" + newDate.getDate().toString();
	} else {
		dayString = newDate.getDate().toString();
	}
	dateString = newDate.getFullYear() + "-" + monthString + "-" + dayString;
	return dateString;
}

function date2str(d,day) {//返回当前时间
	if(day==undefined){
		day=1;
	}
	d.setDate(d.getDate()-day);
	var ret = d.getFullYear() + "-"
	ret += ("00" + (d.getMonth() + 1)).slice(-2) + "-"
	ret += ("00" + (d.getDate())).slice(-2)
	return ret;
}


function SetCookie(name,value)//两个参数，一个是cookie的名子，一个是值
{
    var Days = 30; //此 cookie 将被保存 30 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)//取cookies函数       
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;

}
function delCookie(name)//删除cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
} 
/**
 * 每页显示多少条设置
 * @param {Object} byid 填充下拉框
 * @param {Object} valueName 存储cookie名字
 * @memberOf {TypeName} 
 */
function  fullSelect(byid,valueName){
	
	var pageS = getCookie(valueName);
	if (pageS == null) {
		SetCookie(valueName, 10);
		pageS=10;
	} 
	var sid=$("#"+byid);
	$("#"+byid+" option").each(function(){
			
		 $(this).attr("selected",false);	
		if($(this).val()==pageS)
		{
		
	    $(this).attr("selected",true);		
		}
		
	});
	$("#"+byid).parent().find("h4").html(pageS);
}

function dateInfo(day)
{
		if(day==0)
	{
		$("#statDate").val("");
		$("#timeTo").val("");
	//	$("#statDate").attr("disabled",false);
		//$("#timeTo").attr("disabled",false);
	}else{
		//$("#statDate").attr("disabled",true);
		//$("#timeTo").attr("disabled",true);
		fillDate(day);
	}
}

function checkDate()
{
		var statDate = $("#statDate").val();
			var timeTo = $("#timeTo").val();
			if (statDate == null || statDate == "" || statDate.length < 2) {
				$("#pop_pas").find("p").text("查询起始日期不能为空");
				$("#pop_pas").dialog("open");
				return;
			}
			while(statDate.indexOf("-")>0)
			{
			statDate=statDate.replace("-","/");
			}
            while(timeTo.indexOf("-")>0)
            {
            timeTo=timeTo.replace("-","/");
            }
			if (Date.parse(statDate) > Date
					.parse(timeTo)) {
			$("#pop_pas").find("p").text("查询起始时间不能大于结束时间！");
			$("#pop_pas").dialog("open");

				return;
			}
			if( Date.parse(statDate)>new Date())
			{
		$("#pop_pas").find("p").text("查询起始时间不能大于当前日期！");
			$("#pop_pas").dialog("open");

				return;
			}
			
			$(".pop-loading").show();
			productStatDay_Show();
}

//移除错误提示信息
function removeIcoErr(spanId){
$("#"+spanId).siblings("span").remove();
}
//添加错误提示信息
function addMessage(spanId, message){
	 var tmp=$("<span class='ico err'>"+message+"</span>");
	 $("#"+spanId).after(tmp);
	
}

/**
 *  验证特殊字符 
*/

function containSpecial( s )    
{    
    var containSpecial = RegExp(/[(\~)(\!)(\@)(\#)(\$)(\%)(\^)(\&)(\*)(\-)(\_)(\+)(\=)(\[)(\])(\|)(\\)(\;)(\:)(\')(\")(\,)(\.)(\/)(\<)(\>)(\?)(\)]+/);    
    return ( containSpecial.test(s) );    
}

function init(){
$(".tabbed").find("li").click(function(){
  $(".tabbed").find("li").attr("className","");
  $(this).attr("className","current");
  var text=$("#showDate").text().replace(/^\s+/, '');
  text=text.substring(2,text.length);
  var showDateUser=$("#showDateUser").text().replace(/^\s+/, '');
  showDateUser=showDateUser.substring(2,showDateUser.length);
  
  var idName= $(this).attr("id");
  if(idName=="rpdDay"){
	  dayType="day";
      $("#showDate").text("每日"+text)
      $("#showDateUser").text("每日"+showDateUser)
  }else if(idName=="rpdWeek"){
	   dayType="week";
	    $("#showDate").text("每周"+text)
	    $("#showDateUser").text("每周"+showDateUser)
  }else if(idName=="rpdMonth"){
	   dayType="month";
	    $("#showDate").text("每月"+text)
	    $("#showDateUser").text("每月"+showDateUser)
  }
  queryPara=""
  productStatDay_Show();
});
$("#statDate").change(function(){
	$("#pageSize option:nth-child(1)").attr("selected", "selected");
	
});
$("#timeTo").change(function(){
	$("#pageSize option:nth-child(1)").attr("selected", "selected");
	
});

}

